﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using LongNet.Util;
using LongNet.Web;
using LongNet.URLRewriter.Config;

namespace LongNet.Config
{
     /// <summary>
    /// Represents a configuration element(section) for LongNet in a xml file or app config file.
    /// </summary>
    public class LongNetConfigSection
    {
        #region Fields

        internal static LongNet.Util.LogManager.Logger logger = LongNet.Util.LogManager.GetCurrentClassLogger();
        internal string configPath = null;
        internal const string ConfigSectionName = "LongNet";
        internal static class PropertyName
        {
            internal const string AutoReload = "autoReload";
        }

        internal bool autoReload = false;
        internal Dictionary<string, string> variable = null;
        internal CachingConfigElement cachingConfig = new CachingConfigElement();
        //路由LongNet.URLRewriter.ModuleRewriter
        internal WebConfigElement webConfig = new WebConfigElement();

        internal Dictionary<string, string> variables = ConfigHelper.CreateDictionary<string>();
        internal List<KeyValuePair<string, string>> baseVariables = new List<KeyValuePair<string, string>>()
        {
            new KeyValuePair<string, string>("HostName", Utils.HostName),
            new KeyValuePair<string, string>("AppBaseDirectory", Utils.AppBaseDirectory),
            new KeyValuePair<string, string>("IpAddress", WebUtils.IpAddress),
            new KeyValuePair<string, string>("Url", WebUtils.Url),
            new KeyValuePair<string, string>("ReferrerUrl", WebUtils.ReferrerUrl),
            new KeyValuePair<string, string>("ApplicationPath", WebUtils.ApplicationPath)
        };

        #endregion

        #region Internal Properties And Methods

        /// <summary>
        /// Gets the config file path which should be watched for changes.
        /// </summary>
        internal virtual string ConfigPath
        {
            get { return null; }
        }

        /// <summary>
        /// Called by <see cref="ConfigSectionHandler"/> when the configuration file changes.
        /// </summary>
        /// <returns>A new instance of <see cref="LongNetConfigSection" /> that represents the updated configuration.</returns>
        internal virtual LongNetConfigSection Reload()
        {
            return this;
        }

        #endregion

        #region Config Properties And Elements

        /// <summary>
        /// Gets the value indicating whether the configuration file
        /// should be watched for changes and reloaded automatically when changed.
        /// </summary>
        public bool AutoReload
        {
            get { return this.autoReload; }
            internal set { this.autoReload = value; }
        }

        /// <summary>
        /// Gets the variable collection of the <see cref="LongNetConfigSection"/>.
        /// </summary>
        public IDictionary<string, string> Variable
        {
            get
            {
                return variable ?? (variable = new Dictionary<string, string>(variables));
            }
        }

        ///// <summary>
        ///// Gets the LongNet.Caching namespace configuration.
        ///// </summary>
        //public CachingConfigElement CachingConfig
        //{
        //    get { return this.cachingConfig; }
        //    internal set { this.cachingConfig = value; }
        //}

        ///// <summary>
        ///// Gets the LongNet.Data namespace configuration.
        ///// </summary>
        //public DataConfigElement DataConfig
        //{
        //    get { return this.dataConfig; }
        //    internal set { this.dataConfig = value; }
        //}

        ///// <summary>
        ///// Gets the LongNet.Net namespace configuration.
        ///// </summary>
        //public NetConfigElement NetConfig
        //{
        //    get { return this.netConfig; }
        //    internal set { this.netConfig = value; }
        //}
       
        /// <summary>
        /// Gets the LongNet.Web namespace configuration.
        /// </summary>
        public WebConfigElement WebConfig
        {
            get { return this.webConfig; }
            internal set { this.webConfig = value; }
        }

        #endregion
    }


    public static class UrlRewriterRule
    { 
          

        public static RewriterRuleCollection config;
       

        static UrlRewriterRule()
        {
            //路由LongNet.URLRewriter.ModuleRewriter
           //config=ConfigSectionHandler.Configuration.WebConfig.RewriterConfig;
        }

    }
}
